/*
 * dac.c
 *
 *  Created on: 14-08-2012
 *      Author: Mati
 */

#include "dac.h"
#define OFFSET 20 //zmierzono offset 20mV

void DAC_Config()
{
	LPC_PINCON->PINSEL1 &= ~(0b10<<20);
	LPC_PINCON->PINSEL1 |=  (0b10<<20);	//
}

void ValueDAC(uint16_t voltage_in_mV)	//max 3300mV
{
	uint16_t value;
	float temp = 0;
	temp = (float)(voltage_in_mV-OFFSET)*(float)0.3103;				//1024/3300 = 0,3103	;3,3 * 9,091 - 9,091 nachylenie wzmocnienia wzmacniacza
	value = ((uint16_t) temp );		//

	LPC_DAC->DACR &= ~0x3FF << 6;		//clear last dac value
	LPC_DAC->DACR |= (value&0x3FF) << 6;
	temp = (float) voltage_in_mV;
	Send(PMarker.dac_voltage, (uint8_t*) &temp);
	//return (float) (voltage_in_mV*9.18);					//9.18 - wzmocnienie ukladu analogowego
}
